import axios from 'axios'

const instance = axios.create({
  baseURL: 'http://kumanxuan1.f3322.net:8001',
  timeout: 5000
})

// request -> response -> then
// 请求拦截器
instance.interceptors.request.use(config => {
  // 判断用户有没有登录
  const token = localStorage.getItem('token')
  if (token) {
    // 添加请求头 X-Nideshop-Token: token
    config.headers['X-Nideshop-Token'] = token
  }
  return config
})

// 响应拦截器
instance.interceptors.response.use(res => {
  //
  return res.data
})

export default instance
